<?php

namespace app\common\model;

use think\Model;

class Base extends Model
{
    /**
     * 新增数据
     * @param array $data
     * @return int|string
     */
    public function add_data(array $data)
    {
        $time = time();
        if ($this->autoWriteTimestamp) {
            if ($this->createTime) {
                $data[$this->createTime] = $time;
            }
            if ($this->updateTime) {
                $data[$this->updateTime] = $time;
            }
        }
        return $this->insert($data, true);
    }

    /**
     * 更新数据
     * @param array $data
     * @param array $where
     * @return mixed
     */
    public function save_data(array $data, array $where = [])
    {
        $time = time();
        if ($this->autoWriteTimestamp) {
            if ($this->updateTime) {
                $data[$this->updateTime] = $time;
            }
        }
        return $this->where($where)->update($data);
    }
}